package fan;

import java.util.Iterator;
import java.util.TreeSet;

/**
 * Created with IntelliJ IDEA.
 * ClassName: EmployeeTest
 * Package: fan
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-09-04
 * Time: 21:01
 */

public class EmployeeTest{
    public static void main(String[] args) {

        //1.实现Comparable接口 并按照name排序

        TreeSet<Employee> set = new TreeSet<>();

        Employee e1 = new Employee("HanMeimei",18,new MyData(1998,12,12));
        Employee e2 = new Employee("Lilei",20,new MyData(1996,1,12));
        Employee e3 = new Employee("Lihua",17,new MyData(1997,5,18));
        Employee e4 = new Employee("Zhanglei",15,new MyData(1999,2,12));
        Employee e5 = new Employee("HanMeimei",22,new MyData(1995,8,8));

        //fan.Employee cannot be cast to java.lang.Comparable 一定是要实现fan.Employee cannot be cast to java.lang.Comparable
        set.add(e1);
        set.add(e2);
        set.add(e3);
        set.add(e4);
        set.add(e5);

        //遍历
        Iterator<Employee> iterator = set.iterator();
        while (iterator.hasNext()){
            //类中重写了toString 直接调用就可以输出
            Employee next = iterator.next();
            System.out.println(next);
        }


    }
}
